package com.guigu.basedservice.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.basedservice.entity.BaseCarType;
import com.guigu.basedservice.mapper.BaseCarTypeMapper;
import com.guigu.basedservice.service.BaseCarTypeService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.guigu.basedservice.utils.UniqueNumberGenerator;
import com.guigu.basedservice.vo.BaseCarTypeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 车型 服务实现类
 * </p>
 *
 * @author Heyuhang
 * @since 2024-09-13
 */
@Service
public class BaseCarTypeServiceImpl extends ServiceImpl<BaseCarTypeMapper, BaseCarType> implements BaseCarTypeService {

    @Autowired(required = false)
    private BaseCarTypeMapper baseCarTypeMapper;

    @Override
    public PageInfo<BaseCarType> show(BaseCarTypeVo vo, Integer currentPage, Integer pageSize) {
        QueryWrapper<BaseCarType> queryWrapper=new QueryWrapper<>();
        if (vo!=null) {
            if (vo.getBrandUuid() != null && vo.getBrandUuid() != "") {
                queryWrapper.eq("brand_uuid", vo.getBrandUuid());
            }
            if (vo.getCategoryUuid() != null && vo.getCategoryUuid() != "") {
                queryWrapper.eq("category_uuid", vo.getCategoryUuid());
            }
            if (vo.getSaleName() != null && vo.getSaleName() != "") {
                queryWrapper.eq("sale_name", vo.getSaleName());
            }
        }
        PageHelper.startPage(currentPage,pageSize);
        List<BaseCarType> list=baseCarTypeMapper.selectList(queryWrapper);
        PageInfo<BaseCarType> pageInfo=new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public int add2(BaseCarType baseCarType) {

        baseCarType.setCarTypeUuid(UniqueNumberGenerator.generateUniqueNumber());
        baseCarType.setVersion(BigDecimal.valueOf(0));
        return baseCarTypeMapper.add2(baseCarType);
    }


}
